package core.sceneManager.sceneSection.scene3DSection
{
	import core.MainManager;
	import core.sceneManager.sceneSection.IAnimateBehavior;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	import memory.MemoryRecovery;
	
	import structure.DictionaryAndArrayEvent;
	
	import view.ToolBitmapData;
	/**
	 * 全景里面的动态热点
	 */ 
	public class AnimatePlane extends StaticPlane implements IAnimateBehavior
	{
		private static var autoRefreshed:Dictionary=new Dictionary();                      //是否自动更新图片
		override protected function on_shareData_loaded(e:DictionaryAndArrayEvent):void
		{
			if(e!=null && e.key!=url) return;
			MemoryRecovery.getInstance().gcFun(dataStructure,DictionaryAndArrayEvent.COMPLETE,on_shareData_loaded);
			setMaterial(dataStructure.getContent(url).bitmap);
			play();
		}
		override protected function on_loaded(e:Event):void
		{
			dataStructure.setContent(url,{bitmap:ToolBitmapData.getInstance().drawDisplayObject(loader.content),movieclip:loader.content});//在数据结构里面存储content,供给其他平面使用
			setMaterial(dataStructure.getContent(url).bitmap);
			play();
		}
		override public function dispose():void
		{
			MemoryRecovery.getInstance().gcFun(MainManager.getInstance().stage,Event.ENTER_FRAME,updateGlobalBitmap);
			MemoryRecovery.getInstance().gcFun(MainManager.getInstance().stage,Event.ENTER_FRAME,updateSelfBitmap);
			autoRefreshed=new Dictionary();
			super.dispose();
		}
		////////////////////////////////决定状态//////////////////////////////////
		public function play():void
		{
			if(autoRefreshed[url]==null)                                  //如果是第一次加载这个动画，就负责更新全局图片
			{
				MainManager.getInstance().stage.addEventListener(Event.ENTER_FRAME,updateGlobalBitmap);
				autoRefreshed[url]=true;
			}
			MainManager.getInstance().stage.addEventListener(Event.ENTER_FRAME,updateSelfBitmap);//更新自己的图片
		}
		public function pause():void
		{
			MemoryRecovery.getInstance().gcFun(MainManager.getInstance().stage,Event.ENTER_FRAME,updateSelfBitmap);
		}
		public function resume():void
		{
			MainManager.getInstance().stage.addEventListener(Event.ENTER_FRAME,updateSelfBitmap);
		}
		private function updateGlobalBitmap(e:Event):void//更新全局图片
		{
			var mc:MovieClip=dataStructure.getContent(url).movieclip;
			dataStructure.getContent(url).bitmap=ToolBitmapData.getInstance().drawDisplayObjectCustom(400,400,mc);
		}
		private function updateSelfBitmap(e:Event):void//更新自己的图片
		{
			plane.material.bitmap=dataStructure.getContent(url).bitmap;
		}
	}
}